package com.wptai.disconf.client.data;

import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * disconf 所需的配置实体类
 */

@Data
public class DisconfData {

    public static List<String> paramList = new ArrayList<>();

    public static String APPLICATION_FILE_NAME = "application-wptai.yml";
    public static String DISCONF_FILE_NAME = "disconf.properties";

    //disconf 参数配置
    public static String DISCONF_ENABLE = "wptai.disconf.enable";
    public static String DISCONF_SERVER_URL = "wptai.disconf.server.url";
    public static String DISCONF_APP_ENV = "wptai.disconf.app.env";
    public static String DISCONF_APP_VERSION = "wptai.disconf.app.version";
    public static String DISCONF_APP_NAME = "wptai.disconf.app.name";
    public static String DISCONF_SERVER_DEBUG = "wptai.disconf.server.debug";
    public static String DISCONF_CONFIG_IGNORE = "wptai.disconf.config.ignore";
    public static String DISCONF_SERVER_RETRY_TIMES = "wptai.disconf.server.retry_times";
    public static String DISCONF_SERVER_RETRY_SLEEP_SECONDS = "wptai.disconf.server.retry_sleep_seconds";

    //业务配置
    public static String DISCONF_CONFIG_BASE_SCAN = "wptai.disconf.config.base_scan";
    public static String DISCONF_CONFIG_AOTO_RELOAD_FILES = "wptai.disconf.config.aoto_reload_files";

    private String scan;
    private String autoReloadFiles;


    static {
        paramList.add(DISCONF_ENABLE);
        paramList.add(DISCONF_SERVER_URL);
        paramList.add(DISCONF_APP_ENV);
        paramList.add(DISCONF_APP_VERSION);
        paramList.add(DISCONF_APP_NAME);
        paramList.add(DISCONF_SERVER_DEBUG);
        paramList.add(DISCONF_CONFIG_IGNORE);
        paramList.add(DISCONF_SERVER_RETRY_TIMES);
        paramList.add(DISCONF_SERVER_RETRY_SLEEP_SECONDS);
        paramList.add(DISCONF_CONFIG_BASE_SCAN);
        paramList.add(DISCONF_CONFIG_AOTO_RELOAD_FILES);
    }

    public List<String> getAutoReloadFileList() {
        if(autoReloadFiles == null || autoReloadFiles.length() <= 0){
            return null;
        }
        String [] files = autoReloadFiles.split(";");
        List<String> autoReloadFileList = new ArrayList();
        for (String file:files) {
            autoReloadFileList.add(file);
        }
        return autoReloadFileList;
    }


    public static String getContentDisconfPropertiesVM(){
        return "enable.remote.conf=${wptai_disconf_enable}\n" +
                "conf_server_host=${wptai_disconf_server_url}\n" +
                "env=${wptai_disconf_app_env}\n" +
                "version=${wptai_disconf_app_version}\n" +
                "app=${wptai_disconf_app_name}\n" +
                "debug=${wptai_disconf_server_debug}\n" +
                "ignore=$!{wptai_disconf_config_ignore}\n" +
                "conf_server_url_retry_times=$!{wptai_disconf_server_retry_times}\n" +
                "conf_server_url_retry_sleep_seconds=$!{wptai_disconf_server_retry_sleep_seconds}";
    }


}
